package com.jt.tenant.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.jt.tenant.R;
import com.jt.tenant.app.JTApplication;
import com.jt.tenant.conn.GetMyOrder4;
import com.jt.tenant.widget.Tools;

import java.util.List;

/**
 * Created by Administrator on 2016/4/7.
 */
public class MyOrderRefuelAdapter extends BaseAdapter {

    private Context context;

    private List<GetMyOrder4.OrderList> list;

    private OnCancelListener onCancelListener;

    public MyOrderRefuelAdapter(Context context, List<GetMyOrder4.OrderList> list, OnCancelListener onCancelListener) {

        this.context = context;

        this.list = list;
        this.onCancelListener = onCancelListener;

    }

    @Override
    public int getCount() {

        return list.size();

    }

    @Override
    public Object getItem(int position) {

        return list.get(position);

    }

    @Override
    public long getItemId(int position) {

        return position;

    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {

        ViewHolder holder = null;

        if (convertView == null) {

            convertView = View.inflate(context, R.layout.item_myorder_refuel, null);

            JTApplication.ScaleScreenHelper.loadView((ViewGroup) convertView);

            holder = new ViewHolder();

            holder.tv_oil_order_code = (TextView)convertView.findViewById(R.id.tv_oil_order_code);
            holder.tv_oil_order_date = (TextView)convertView.findViewById(R.id.tv_oil_order_date);
            holder.tv_oil_order_num = (TextView)convertView.findViewById(R.id.tv_oil_order_num);
            holder.tv_oil_order_price = (TextView)convertView.findViewById(R.id.tv_oil_order_price);
            holder.tv_oil_order_station = (TextView)convertView.findViewById(R.id.tv_oil_order_station);
//            holder.tv_order_state = (TextView)convertView.findViewById(R.id.tv_order_state);
//            holder.lin_order_state = (LinearLayout) convertView.findViewById(R.id.lin_order_state);



            convertView.setTag(holder);

        } else {

            holder = (ViewHolder) convertView.getTag();

        }

        holder.tv_oil_order_date.setText("日期："+Tools.getTime1(list.get(position).GASAPPOINTMENTTIME));

        holder.tv_oil_order_num.setText("加油量："+Tools.F_num(list.get(position).NUM)+"升");

        holder.tv_oil_order_price.setText("获得积分："+Tools.F_num(list.get(position).INTEGRALCOUNT));

        if(Tools.F_num(list.get(position).NUM).equals("0")||Tools.F_num(list.get(position).INTEGRALCOUNT).equals("0")){

            holder.tv_oil_order_code.setText("订单编号："+list.get(position).GASCODE+"(预约中)");

        }else {

            holder.tv_oil_order_code.setText("订单编号："+list.get(position).GASCODE);

        }

        holder.tv_oil_order_station.setText("加油站："+list.get(position).GAS_NAME);



//        状态:0已预约未支付 1已加油 2取消预约 3已支付未加油
//        switch (list.get(position).GASSTATE){
//            case "0":
//
//                holder.tv_order_state.setText("取消");
//
//                holder.lin_order_state.setBackgroundColor(Color.parseColor("#eb3604"));
//
//                break;
//            case "1":
//
//                holder.tv_order_state.setText("已完成");
//
//                holder.lin_order_state.setBackgroundColor(Color.parseColor("#80d71a"));
//
//
//
//                break;
//            case "2":
//
//
//
//                break;
//            case "3":
//
//                holder.tv_order_state.setText("取消");
//
//                holder.lin_order_state.setBackgroundColor(Color.parseColor("#eb3604"));
//
//                break;
//        }




        return convertView;

    }

    public interface OnCancelListener{
        public void onCancel(String orderId);
    }

    class ViewHolder {
        private TextView tv_oil_order_code;
        private TextView tv_oil_order_date;
        private TextView tv_oil_order_num;
        private TextView tv_oil_order_price;
        private TextView tv_oil_order_station;
//        private TextView tv_order_state;
//        private LinearLayout lin_order_state;


    }
}
